<?php
/**
* 视频中心
* @DateTime 2017-09-18
* @author xyl
*/
class Video extends Admin_Controller
{
	
	function __construct()
	{
		parent::__construct();
		$this->load->model('Video_model','video');
		
	}

    /**
     * 设置视频
     * @author XYL
     * @DateTime 2018-06-04
     */
    public function Video_edit()
    {
        $vdata['info'] = $this->video->getVideoDetail(array('id'=>1));
        $this->load->view('Video/addVideo',$vdata);
    }
    /**
     * 视频中心首页
     * @DateTime 2017-09-18
     * @author xyl
     * @return   [type]     [description]
     */
    public function index()
    {
    	$ajaxUrl = base_url().'Admin/Video/ajaxGetVideoList';
    	if($_POST){
    		$data = $this->input->post();
    		if(isset($data['name'])){
    			$ajaxUrl = $ajaxUrl.'?'.'name='.$data['name'];
    			$vdata['search_name'] = $data['name'];
    		}else{
                $ajaxUrl = $ajaxUrl.'?'.'type='.$data['type'].'&start_time='.$data['start_time'].'&end_time='.$data['end_time'];
            }
        }
        $vdata['ajaxUrl'] = $ajaxUrl;
        $this->load->view('Video/index',$vdata);
    }

	/**
	 * ajax获取用户列表
     * @DateTime 2017-09-04
     * @author xyl 
	 * @return [type] [description]
	 */
	public function ajaxGetVideoList()
    {
      $where = $_GET;
      $user_list = $this->video->ajaxGetVideoList($_GET['iDisplayLength'],$_GET['iDisplayStart'],$where);
      $return = array(
         'aaData'=>$user_list['data'],
         'iTotalRecords'=>count($user_list['data']),
         'iTotalDisplayRecords'=>$user_list['total'],
     );
      echo json_encode($return);
  } 

    /**
     * 添加或编辑资讯
     * @DateTime 2017-09-18
     * @author xyl
     */
    public function addVideo($id = false)
    {
        $vdata = array();

        if ($_POST) {
            $post = $this->input->post();
            $res = $this->video->addVideo($post);
            $this->handleResult($res);
        }else{
            if (isset($id) && !empty($id)) {
                $vdata['info'] = $this->video->getVideoDetail(array('id'=>$id));
            }
            $this->load->view('Video/addVideo',$vdata);
        }
    }

    /**
     * 视频上线下线，用于首页视频循环播放
     * @DateTime 2017-09-18
     * @author xyl
     */
    public function setRoll()
    {
        $post = $this->input->post();
        $res = $this->video->setRoll($post);
        $this->handleResult($res);
    }

}